package com.baosight.sczx.zm.cp.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;
import com.baosight.iplat4j.ef.ui.tree.TreeService;
import com.baosight.iplat4j.ep.QueryMap;
import com.baosight.sczx.common.zm.basetools.StaticTools;

/**
 * 生产计划最外层，树框架
 * @author wealupa
 * By. 严洪浩
 */
public class ServiceZMCP07 extends TreeService {

	private static final int date = 1201;
	
	@SuppressWarnings("rawtypes")
	public EiInfo query(EiInfo inInfo) {
		QueryMap queryInfo = QueryMap.getQueryMap(inInfo);
		String p = (String) queryInfo.get(TreeConstants.TREE_NODE);
		List children = new ArrayList();
		if (p == null) {
			p = "$";
		} 
		String[] ps=p.split("-");
		if ("$".equals(p)) {//$
			children = this.getTopNodes();
		} else if(ps.length==1) {//2016
			children = this.getChildNodes(p);
		} else {//2016-1
			children = this.getChild2Nodes(p);
		}

		EiInfo outInfo = new EiInfo();
		EiBlock block = outInfo.addBlock(p);
		block.setBlockMeta(initMetaData());
		block.setRows(children);
		return outInfo;
	}
	
	/**子节点
	 * <p>Function: getChildNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM57</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-3-24下午06:10:18 张坤
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public List getChildNodes(String arg0) {
		return getAllMonths(arg0);
	}
	
	@SuppressWarnings("rawtypes")
	public List getChild2Nodes(String arg0) {
		return getAllTypes(arg0);
	}
	/**根节点
	 * <p>Function: getTopNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM57</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-3-24下午06:10:18 张坤
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public List getTopNodes() {
		List<Map> _topNodes = new ArrayList<Map>();
		String dateforDay = StaticTools.getDateforDay();
		int dateForday = Integer.parseInt(dateforDay);
				
		String Year =StaticTools.getYear();
		int year = Integer.parseInt(Year);
        
		if(dateForday > date || dateForday == date){
			Map<String, String> _tempMap = null;
			_tempMap = new HashMap<String, String>();
			_tempMap.put("label", String.valueOf(year+1));
			_tempMap.put("text", (year+1)+"年");
			_tempMap.put("leaf","0");
			_topNodes.add(_tempMap);
			
			_tempMap = new HashMap<String, String>();
			_tempMap.put("label", year+"");
			_tempMap.put("text", year+"年");
			_tempMap.put("leaf","0");
			_topNodes.add(_tempMap);
			
			_tempMap = new HashMap<String, String>();
			_tempMap.put("label", year-1+"");
			_tempMap.put("text", (year-1)+"年");
			_tempMap.put("leaf","0");
			_topNodes.add(_tempMap);
		}
		else{

			Map<String, String> _tempMap = null;
			_tempMap = new HashMap<String, String>();
			_tempMap.put("label", year+"");
			_tempMap.put("text", year+"年");
			_tempMap.put("leaf","0");
			_topNodes.add(_tempMap);
			
			_tempMap = new HashMap<String, String>();
			_tempMap.put("label", year-1+"");
			_tempMap.put("text", (year-1)+"年");
			_tempMap.put("leaf","0");
			_topNodes.add(_tempMap);
			
			_tempMap = new HashMap<String, String>();
			_tempMap.put("label", year-2+"");
			_tempMap.put("text", (year-2)+"年");
			_tempMap.put("leaf","0");
			_topNodes.add(_tempMap);
		}
		return _topNodes;
	}
	
	/**列定义
	 * <p>Function: initMetaData</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM57</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-3-24下午06:10:18 张坤
	 * </p>
	 *
	 */
	@Override
	public EiBlockMeta initMetaData() {
		EiBlockMeta eiMetadata = new EiBlockMeta();

		EiColumn eiColumn = new EiColumn("label");
		eiColumn.setDescName("label");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("text");
		eiColumn.setDescName("text");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("leaf");
		eiColumn.setDescName("leaf");
		eiColumn.setType(EiConstant.COLUMN_TYPE_NUMBER);
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		return eiMetadata;
	}
	
	/**
	 * 构造子节点数据
	 * <p>Function: getAllMonths</p>
	 * <p>Description: </p>
	 * <p>return value:List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-3-24上午09:16:17 张坤
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private List getAllMonths(String arg0){
		List children = new ArrayList();
		Map _tempMap = null;
		
		for(int i = 1; i <= 12; i++){
			_tempMap = new HashMap<String, String>();
			_tempMap.put("label", arg0+"-"+i);
			_tempMap.put("text", i+"月");
			_tempMap.put("leaf","1");
			children.add(_tempMap);
		}
		return children;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private List getAllTypes(String arg0){
		List children = new ArrayList();
		Map _tempMap = null;
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP01");
		_tempMap.put("text", "原煤计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP03");
		_tempMap.put("text", "掘进计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP05");
		_tempMap.put("text", "抽采计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP07");
		_tempMap.put("text", "一通三防计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP09");
		_tempMap.put("text", "机电运输计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP0B");
		_tempMap.put("text", "建造粉尘计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);  
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP0D");
		_tempMap.put("text", "质量整治计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);  
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP0F");
		_tempMap.put("text", "全岩找顶计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);  
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP0H");
		_tempMap.put("text", "重结点项目计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);  
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP0J");
		_tempMap.put("text", "规程设计计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);  
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", arg0+"-"+"ZMCP0L");
		_tempMap.put("text", "文明生产计划");
		_tempMap.put("leaf","1");
		children.add(_tempMap);   
		
		return children;
	}

}
